package handlers

import (
	"dashboard/data"
	"encoding/json"
	"fmt"
	"net/http"
)

func UpdateProblemHandler(w http.ResponseWriter, r *http.Request) {
	var newProblem data.Problem
	err := json.NewDecoder(r.Body).Decode(&newProblem)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	err = data.Problems.AddOrUpdateProblem(newProblem)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	// Устанавливаем статус 200 OK
	response := fmt.Sprintf("OK\n")
	w.Write([]byte(response))
}
